
class Stack <T> {
    Object [] data;
    int sp = 0;
    int max = 10;

    public Stack() {
        data = new Object[max];
    }

    public Stack(int len) {
        data = new Object[len];
    }

    public boolean empty() {
        return (sp == 0) ? true : false;
    }

    public boolean full() {
        return (sp == max) ? true : false;
    }

    public Stack push(T inputData) {
        if (full())
            return null;

        this.data[sp++] = inputData;
        return this;
    }

    public T pop() {
        return (T)this.data[--sp];
    }
}

public class genericTest {
    static public void main(String [] args) {
        int i, num;
        // Stack <Integer> stack = new Stack<Integer>(10);
        // Stack <Double> stack = new Stack<>(10.35676);
        // Stack <String> stack = new Stack<>("hello");

        // System.out.printf("stack = " + stack.get());

        Stack <Integer> stack = new Stack<>();

        System.out.printf("rand: ");
        for (i = 0; i < 20; i++) {
            num = (int)(Math.random() * 100);
            if (stack.push(num) == null)
                break;
            System.out.printf("%d ", num);
        }
        System.out.println();

        System.out.printf("pop: ");
        for (i = 0; i < 20; i++) {
            if (stack.empty())
                break;
            System.out.printf("%d ", stack.pop());
        }
        System.out.println();
    }
}
